﻿using Microsoft.Practices.Unity.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Artech.Core
{
    /// <summary>
    /// Context provider using a thread static variable as the context storage.
    /// </summary>
    public class ThreadStaticContextProvider: IContextProvider
    {
        [ThreadStatic]
        private static ContextItemCollection items;

        /// <summary>
        /// Gets the context items.
        /// </summary>
        /// <returns>
        /// A <see cref="ContextItemCollection" /> including all of <see cref="ContextItem" />.
        /// </returns>
        public ContextItemCollection GetContextItems()
        {
            return items ?? (items = new ContextItemCollection());
        }

        /// <summary>
        /// Sets the context items.
        /// </summary>
        /// <param name="contextItems">The context items.</param>
        public void SetContextItems(ContextItemCollection contextItems)
        {
            Guard.ArgumentNotNull(contextItems, "contextItems");
            items = contextItems;
        }
    }
}